package lxt.dao.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.CostPetrolDao;
/**
 * 加油管理dao
 * @author Lit
 *
 */
public class CostPetrolDaoImpl extends ABseDaoImpl implements CostPetrolDao {

	@SuppressWarnings("unchecked")
	public List<Object> loadAllCostPetrol(String truckId, String driverId,
			int offset, int length) {
		StringBuffer hql = new StringBuffer("Select tc,td.name,tp from CostPetrol tc,DriverInfo td,Parameter tp where tc.driverId = td.id And tc.petrolType = tp.id.paramKey And tp.id.paramType = ? ");
		ArrayList<Object> param = new ArrayList<Object>();
		param.add("petrolType");
		if(truckId!=null&&!truckId.equals("")){
			hql.append(" And tc.truckId like ? ");
			param.add("%"+truckId+"%");
		}
		if(driverId!=null&&!driverId.equals("")){
			hql.append(" And td.name like ? ");
			param.add("%"+driverId+"%");
		}
		
		return (List<Object>)this.queryForPage(hql.toString(), param, offset, length);
	}

	public int loadAllCostPetrolCount(String truckId, String driverId) {
		StringBuffer hql = new StringBuffer("Select tc,td.name from CostPetrol tc,DriverInfo td where tc.driverId = td.id ");
		ArrayList<Object> param = new ArrayList<Object>();
		if(truckId!=null&&!truckId.equals("")){
			hql.append(" And tc.truckId like ? ");
			param.add("%"+truckId+"%");
		}
		if(driverId!=null&&!driverId.equals("")){
			hql.append(" And td.name like ? ");
			param.add("%"+driverId+"%");
		}
		return this.getAllRowCount(hql.toString(), param);
	}

}
